package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.SystemUserMapper;
import com.tzbank.back.service.SystemUserService;
import com.tzbank.entity.backstage.SystemUser;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

@Service
public class SystemUserServiceImpl implements SystemUserService {

	@Autowired
	private SystemUserMapper systemUserMapper;

	@Transactional
	@Override
	public Map<String, Object> deleteSystemUserByAutoId(int autoId) throws Exception{
		this.systemUserMapper.deleteSystemUserByAutoId(autoId);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> insertSystemUser(SystemUser systemUser) throws Exception{
		systemUser.setValid("Y");
		systemUser.setDeleteFlag("N");
		systemUser.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		systemUser.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.systemUserMapper.insertSystemUser(systemUser);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> selectSystemUser() throws Exception{
		List<SystemUser> systemUsers = this.systemUserMapper.selectSystemUser();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), systemUsers);
	}

	@Override
	public Map<String, Object> selectSystemUserByAutoId(int autoId) throws Exception{
		SystemUser systemUser = this.systemUserMapper.selectSystemUserByAutoId(autoId);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), systemUser);
	}

	@Transactional
	@Override
	public Map<String, Object> updateSystemUser(SystemUser systemUser) throws Exception{
		systemUser.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.systemUserMapper.updateSystemUser(systemUser);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
